/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 - 2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.form.server.spring.context;

import com.genia.toolbox.web.gwt.form.client.value.DataIdentifier;
import com.genia.toolbox.web.gwt.form.client.value.FormValues;
import com.genia.toolbox.web.gwt.form.client.value.impl.DataIdentifierImpl;

/**
 * context information for the current handled form.
 */
public interface FormProviderContext
{

  /**
   * the form providers methods.
   */
  public enum CalledMethod
  {
    /**
     * the getForm method.
     */
    getForm,
    /**
     * the getInitialValue method.
     */
    getInitialValue
    {
      /**
       * complete the {@link FormProviderContext} depending on the method.
       * 
       * @param formProviderContext
       *          the {@link FormProviderContext} to complete
       * @param args
       *          the arguments of the method
       */
      @Override
      public void completeFormProviderContext(FormProviderContext formProviderContext, Object[] args)
      {
        if (args != null && args.length == 1 && (args[0] instanceof DataIdentifier)) {
          formProviderContext.setDataIdentifier((DataIdentifier) args[0]);
        }
      }
    },
    /**
     * the saveForm method.
     */
    saveForm
    {
      /**
       * complete the {@link FormProviderContext} depending on the method.
       * 
       * @param formProviderContext
       *          the {@link FormProviderContext} to complete
       * @param args
       *          the arguments of the method
       */
      @Override
      public void completeFormProviderContext(FormProviderContext formProviderContext, Object[] args)
      {
        formProviderContext.setDataIdentifier(((FormValues) args[0]).getDataIdentifier());
      }
    },
    /**
     * the getSuggestions method.
     */
    getSuggestions
    {
      /**
       * complete the {@link FormProviderContext} depending on the method.
       * 
       * @param formProviderContext
       *          the {@link FormProviderContext} to complete
       * @param args
       *          the arguments of the method
       */
      @Override
      public void completeFormProviderContext(FormProviderContext formProviderContext, Object[] args)
      {
        formProviderContext.setDataIdentifier((DataIdentifier) args[0]);
      }
    },
    /**
     * the getDisplayString method.
     */
    getDisplayString;

    /**
     * complete the {@link FormProviderContext} depending on the method.
     * 
     * @param formProviderContext
     *          the {@link FormProviderContext} to complete
     * @param args
     *          the arguments of the method
     */
    public void completeFormProviderContext(FormProviderContext formProviderContext, Object[] args)
    {
      formProviderContext.setDataIdentifier(new DataIdentifierImpl());
    }
  };



  /**
   * getter for the dataIdentifier property.
   * 
   * @return the dataIdentifier
   */
  public abstract DataIdentifier getDataIdentifier();



  /**
   * setter for the dataIdentifier property.
   * 
   * @param dataIdentifier
   *          the dataIdentifier to set
   */
  public abstract void setDataIdentifier(DataIdentifier dataIdentifier);



  /**
   * getter for the formIdentifier property.
   * 
   * @return the formIdentifier
   */
  public abstract String getFormIdentifier();



  /**
   * setter for the formIdentifier property.
   * 
   * @param formIdentifier
   *          the formIdentifier to set
   */
  public abstract void setFormIdentifier(String formIdentifier);



  /**
   * getter for the calledMethod property.
   * 
   * @return the calledMethod
   */
  public abstract CalledMethod getCalledMethod();



  /**
   * setter for the calledMethod property.
   * 
   * @param calledMethod
   *          the calledMethod to set
   */
  public abstract void setCalledMethod(CalledMethod calledMethod);
}
